package com.example.demospringmybatisplus.listener;

import com.example.demospringmybatisplus.entity.Invoice;
import com.example.demospringmybatisplus.enums.InvoiceActionEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * 发票操作监听器管理器
 *
 * @author huahua
 * @DATE 2025/8/2
 **/
public class InvoiceActionListenerManager {
    private List<InvoiceActionListener> actionListenerList = new ArrayList<>();

    public void addListener(InvoiceActionListener observer) {
        actionListenerList.add(observer);
    }

    /**
     * 通知所有监听器
     * 管理并通知所有已注册的监听器
     * 当发票发生操作时候，向所有注册的监听器发送通知
     *
     * @param action
     * @param current
     * @param before
     */
    public void notify(InvoiceActionEnum action, Invoice current, Invoice... before) {
        for (InvoiceActionListener listener : actionListenerList) {
            listener.notify(action, current, before);
        }
    }
}
